package com.biostime.qdingding.modules.qd.api;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.biostime.qdingding.common.api.FastResponse;
import com.biostime.qdingding.common.api.ListResponse;
import com.biostime.qdingding.common.web.BaseController;
import com.biostime.qdingding.modules.cms.service.ArticleService;
import com.biostime.qdingding.modules.qd.api.dto.ParentGuidanceDto;
import com.biostime.qdingding.modules.qd.service.AlbumService;
import com.biostime.qdingding.modules.qd.service.CourseService;
import com.biostime.qdingding.modules.qd.service.ParentGuidanceService;

/**
 * 父母指南
 * @author chenweicheng
 * @version 2016-03-12
 */
@RestController
@RequestMapping(value = "${adminPath}/qd/api/parentGuicance")
public class ParentGuidanceApi extends BaseController{
	@Autowired
	ArticleService articleService;
	
	@Autowired
	AlbumService albumService;
	
	@Autowired
	CourseService courseService;
	
	@Autowired
	ParentGuidanceService parentGuidance;
		
	/**
	 * 获取父母指南列表
	 */
	@RequestMapping(value = "getGuidanceList")
	public ListResponse<ParentGuidanceDto> getGuidanceList(String userId,String studentId,HttpServletRequest request) {	
		String message = null;
		int errCode = 0;
		List<ParentGuidanceDto>  dtoList = new ArrayList<ParentGuidanceDto>();
	
		if (userId != null && !userId.equals("") && studentId != null && !studentId.equals("")) {		
			dtoList = courseService.apiGetGuidenceList(studentId);
			
			//通过日期主题年龄段系列查找文章
			if(dtoList != null && !dtoList.isEmpty()){
				for(ParentGuidanceDto  dto : dtoList){
					String serial = dto.getSerial();
					String theme = dto.getTheme();
					String clevel = dto.getClevel();
					String name = clevel+serial+theme;
					dto.setUrl(parentGuidance.getParentGuidanceUrl(request, name)); 
				}
			}
			message = "获取父母指南列表成功";
			errCode = 0;
			
		} else {
			message = "获取父母指南列表失败，参数有误";
			errCode = 1;
		}
		
		return FastResponse.create().errMsg(message).errCode(errCode).list(dtoList);
	}	

}
